package main

import "fmt"

// Definition for singly-linked list.
type ListNode struct {
	Val  int
	Next *ListNode
}

func deleteDuplicates(head *ListNode) *ListNode {
	var tmp *ListNode
	if head == nil || head.Next == nil {
		return head
	}
	tmp = head.Next
	for {
		if tmp == nil {
			return nil
		}
		if head.Val == tmp.Val {
			tmp = tmp.Next
			continue
		}
		if tmp != head.Next {
			head = tmp.Next
		}
		break
	}
	fmt.Println(head.Val)
	if head == nil || head.Next == nil {
		return head
	}
	tmp = &ListNode{}
	tmp.Next = head
	p := head.Next
	for {
		if p.Val != tmp.Next.Val {
			tmp = p
			p = tmp.Next.Next
			continue
		}
		p = p.Next

		fmt.Println(p.Val)
		if p == nil {
			tmp.Next = nil
			break
		}

		if tmp == nil || tmp.Next == nil {
			return head
		}
		tmp.Next.Next = p
	}
	return head
}

func main() {
	var head *ListNode = &ListNode{}
	t := head
	s := []int{1, 2, 3, 3, 4, 4, 5}
	for _, v := range s {
		t.Next = &ListNode{
			Val:  v,
			Next: nil,
		}
		t = t.Next
	}
	head = head.Next
	fmt.Println(deleteDuplicates(head))
}
